package mahjong;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;


/**
 * The JFrame that defines the entire GUI.
 */
@SuppressWarnings("serial")
public class JViewer extends JFrame
{

	/** The actual board drawing area. */
	private Viewer drawingArea;


	/**
	 * Main constructor to use.
	 * @param bn Board name, used in the window title.
	 * @param b Actual Board object.
	 * @param p Player of the board.
	 */
	public JViewer(String bn, Board b, Player p)
	{
		// you may want to rename this
		super("Mahjong: " + bn);

		// add a closing adaptor to respond to window close events
		// this is so you can click on the window-close button on the
		// main frame and it will go away.
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.out.println("Quitting main frame....");
				System.exit(0);
			}
		});

		// Now, add some components to our GUI (without these it's just
		// a big empty frame)

		// the contents of a jframe are not accessed directly, rather
		// you go through the ContentPane, which is guaranteed to be non-null
		Container c = getContentPane();

		// in order to add components like buttons etc, we need a
		// layout manager.  One of the simplest ones is BorderLayout,
		// which conveniently enough is the default.  If not we'd
		// use code like:
		c.setLayout(new BorderLayout());
		drawingArea = new Viewer(b, p);
		TimeManager tm = new TimeManager();
		MenuManager mm = new MenuManager(this, drawingArea, tm);
		drawingArea.setBackground(new Color(101,37,37));
		c.add(drawingArea,BorderLayout.CENTER);
		c.add(tm, BorderLayout.SOUTH);
		// arrange components
		pack();
		setVisible(true);
		setResizable(false);
	}

	/** Getter for actual Board GUI component. 
	 * @return The JPanel containing the board itself. */ 
	public Viewer getViewer()
	{
		return drawingArea;
	}
}
